package com.lune.job.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.lune.job.mapper.StudentMapper;
import com.lune.job.mapper.UserMapper;
import com.lune.job.pojo.ResPageBean;
import com.lune.job.pojo.Student;
import com.lune.job.pojo.User;
import com.lune.job.service.IStudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author Caiyilin
 * @since 2022-03-06
 */
@Service
public class StudentServiceImpl extends ServiceImpl<StudentMapper, Student> implements IStudentService {

    @Autowired
    private StudentMapper studentMapper;

    /**
     * 登录方法
     *
     * @param account
     * @param password
     * @return
     */
    @Override
    public Student login(String account, String password) {
        Student param = new Student();
         param.setAccount(account);
        param.setPassword(password);

        List<Student> list = studentMapper.query(param);
        if (list != null && list.size() > 0) {
            return list.get(0);
        } else {
            return null;
        }

    }

    /**
     * 根据id查询学生
     * @param id
     * @return
     */
    @Override
    public Student detail(Integer id) {
        return studentMapper.selectById(id);
    }

    /**
     * 分页查询所有学生
     * @param currentPage
     * @param size
     * @param student
     * @return
     */
    @Override
    public ResPageBean getAllStudentsByPage(Integer currentPage, Integer size, Student student) {
        Page<Student> page = new Page<>(currentPage, size);
        IPage<Student> studentIPage = studentMapper.getAllStudentsByPage(page,student);
        ResPageBean resPageBean = new ResPageBean(studentIPage.getTotal(), studentIPage.getPages(), studentIPage.getRecords());
        return  resPageBean;

    }

    /**
     * 条件查询学生用户
     * @param student
     * @return
     */
    @Override
    public List<Student> queryByCon(Student student) {
        return studentMapper.queryByCon(student);
    }
}
